function dvf_pseudo = create_psuedo_dvf_vec_volt3d_sliding_IterateVoltage_parfor(patient, volt, flow, ii,jj,kk)
    %(folder,model_folder, static_mask, volt,flow,scans,ii,jj,kk)


pctRunOnAll javaaddpath E:\ParforProgMonv2\java
progressStepSize = 1;
ppm = ParforProgMon('Creating Psuedo Deformation Vector: ',dim(1),  progressStepSize,800, 120);
tic
% mkdir('Psuedo_dvfs')

    dvf_pseudo=zeros(size(ii,2),size(jj,2),3,size(kk,2));
  tic 
%   cd(model_folder)
  
      volt_2d = permute(repmat(volt, [1 patient.dim(2)]),[2,1]);
    flow_2d = permute(repmat(flow, [1 patient.dim(2)]),[2,1]);
    k_2d = permute(repmat([1:length(volt)]', [1 patient.dim(2)]),[2,1]);
    p_volt = polyfit(1:length(volt),volt',15)
    p_flow = polyfit(1:length(flow),flow',15)
    volt_1000 = polyval(p_volt, [1:0.0001:length(volt)]);
    flow_1000 = polyval(p_flow, [1:0.0001:length(volt)]);
dvf_pseudo_u = zeros(patient.dim);
dvf_pseudo_v = zeros(patient.dim);
dvf_pseudo_w = zeros(patient.dim);

parfor slice=1:size(ii,2);
   
    
    constant=load([patient.model_params_folder, sprintf('/constant_%d',slice)]);
    constant_vec_u=constant.data(:,:,1);constant_vec_u=constant_vec_u(:);
    constant_vec_v=constant.data(:,:,2);constant_vec_v=constant_vec_v(:);
    constant_vec_w=constant.data(:,:,3);constant_vec_w=constant_vec_w(:);
    
    alpha=load([patient.model_params_folder,sprintf('/alpha_%d',slice)]);
    alpha_vec_u=alpha.data(:,:,1);alpha_vec_u=alpha_vec_u(:);
    alpha_vec_v=alpha.data(:,:,2);alpha_vec_v=alpha_vec_v(:);
    alpha_vec_w=alpha.data(:,:,3);alpha_vec_w=alpha_vec_w(:);
    
    beta=load([patient.model_params_folder,sprintf('/beta_%d',slice)]);
    beta_vec_u=beta.data(:,:,1);beta_vec_u=beta_vec_u(:);
    beta_vec_v=beta.data(:,:,2);beta_vec_v=beta_vec_v(:);
    beta_vec_w=beta.data(:,:,3);beta_vec_w=beta_vec_w(:);
    
    %     gamma=load(sprintf('gamma_%d',slice));
    %     gamma_vec_u=alpha.data(:,:,1);gamma_vec_u=gamma_vec_u(:);
    %     gamma_vec_v=alpha.data(:,:,2);gamma_vec_v=gamma_vec_v(:);
    %     gamma_vec_w=alpha.data(:,:,3);gamma_vec_w=gamma_vec_w(:);
    
    model_u=[constant_vec_u alpha_vec_u beta_vec_u];% gamma_vec_u];
    model_v=[constant_vec_v alpha_vec_v beta_vec_v];% gamma_vec_v];
    model_w=[constant_vec_w alpha_vec_w beta_vec_w];% gamma_vec_w];
    
    E=[ones(length(model_u),1)  volt_2d(:) flow_2d(:)];
    dvf_fit_u=zeros(size(jj,2)*size(kk,2),1);%,size(ii,2),
    dvf_fit_v=zeros(size(jj,2)*size(kk,2),1);%,size(ii,2),
    dvf_fit_w=zeros(size(jj,2)*size(kk,2),1);%,size(ii,2),
    
    
        E_iterate = E;
    for vox = 1:length(model_u);
%         if mod(vox,1000)==1
%             vox
%         end
        for p = 1:10;
            
            dvf_fit_w(vox)=model_w(vox,:)*E_iterate(vox,:)';
            %             [j,k] = ind2sub(size(volt_2d),vox);
            %             volt_1d = polyval(p_volt, k_2d(vox)+(dvf_fit_w(vox)));
            %             flow_1d = polyval(p_flow, k_2d(vox)+(dvf_fit_w(vox)));
            if round(10000*(k_2d(vox)+(dvf_fit_w(vox))))>0&& round(10000*(k_2d(vox)+(dvf_fit_w(vox))))<length(flow_1000)
                volt_1d = volt_1000(round(10000*(k_2d(vox)+(dvf_fit_w(vox)))));
                flow_1d  =  flow_1000(round(10000*(k_2d(vox)+(dvf_fit_w(vox)))));
                
                E_iterate(vox,:) = [1 volt_1d flow_1d];
            end
        end
    end
    
%     for vox = 1:length(model_u);
%         dvf_fit_u1(vox)=model_u(vox,:)*E(vox,:)';
%         dvf_fit_v1(vox)=model_v(vox,:)*E(vox,:)';
%         dvf_fit_w1(vox)=model_w(vox,:)*E(vox,:)';
%         
%     end
    for vox = 1:length(model_u);
        dvf_fit_u(vox)=model_u(vox,:)*E_iterate(vox,:)';
        dvf_fit_v(vox)=model_v(vox,:)*E_iterate(vox,:)';
        dvf_fit_w(vox)=model_w(vox,:)*E_iterate(vox,:)';
        
    end
    
    %     cd('Psuedo_dvfs');
      
%     dvf_pseudo_u1(slice,jj,kk)=reshape(dvf_fit_u1,size(jj,2),size(kk,2));
%     dvf_pseudo_v1(slice,jj,kk)=reshape(dvf_fit_v1,size(jj,2),size(kk,2));
%     dvf_pseudo_w1(slice,jj,kk)=reshape(dvf_fit_w1,size(jj,2),size(kk,2));
  
    dvf_pseudo_u(slice,jj,kk)=reshape(dvf_fit_u,size(jj,2),size(kk,2));
    dvf_pseudo_v(slice,jj,kk)=reshape(dvf_fit_v,size(jj,2),size(kk,2));
    dvf_pseudo_w(slice,jj,kk)=reshape(dvf_fit_w,size(jj,2),size(kk,2));
 
    
    %          if save_files==1;
    %
    % %         iSaveX( sprintf( 'dvf_pseudo_%d', slice ), dvf_pseudo );
    %     end
    ppm.increment();
    
end
toc
dvf_pseudo(:,:,1,:)=dvf_pseudo_u;
dvf_pseudo(:,:,2,:)=dvf_pseudo_v;
dvf_pseudo(:,:,3,:)=dvf_pseudo_w;






